home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / ADA / GNAT / !gcc / adainc / 2 / ads / a-ststio < prev    next >
Text File  |  1996-02-12  |  6KB  |  166 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                A D A . S T R E A M S . S T R E A M _ I O                 --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.12 $                             --
  10. --                                                                          --
  11. -- This specification is adapted from the Ada Reference Manual for use with --
  12. -- GNAT.  In accordance with the copyright of that document, you can freely --
  13. -- copy and modify this specification,  provided that if you redistribute a --
  14. -- modified version,  any changes that you have made are clearly indicated. --
  15. --                                                                          --
  16. ------------------------------------------------------------------------------
  17.  
  18.  
  19. with Ada.IO_Exceptions;
  20. with System.File_Control_Block;
  21.  
  22. package Ada.Streams.Stream_IO is
  23.  
  24.    type Stream_Access is access all Root_Stream_Type'Class;
  25.  
  26.    type File_Type is limited private;
  27.  
  28.    type File_Mode is (In_File, Out_File, Append_File);
  29.  
  30.    --  The following representation clause allows the use of unchecked
  31.    --  conversion for rapid translation between the File_Mode type
  32.    --  used in this package and System.File_IO.
  33.  
  34.    for File_Mode use
  35.      (In_File     => 0,  -- System.FIle_IO.File_Mode'Pos (In_File)
  36.       Out_File    => 2,  -- System.File_IO.File_Mode'Pos (Out_File)
  37.       Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
  38.  
  39.    type Count is new Stream_Element_Offset;
  40.  
  41.    subtype Positive_Count is Count range 1 .. Count'Last;
  42.    --  Index into file, in stream elements
  43.  
  44.    ---------------------
  45.    -- File Management --
  46.    ---------------------
  47.  
  48.    procedure Create
  49.      (File : in out File_Type;
  50.       Mode : in File_Mode := Out_File;
  51.       Name : in String := "";
  52.       Form : in String := "");
  53.  
  54.    procedure Open
  55.      (File : in out File_Type;
  56.       Mode : in File_Mode;
  57.       Name : in String;
  58.       Form : in String := "");
  59.  
  60.    procedure Close  (File : in out File_Type);
  61.    procedure Delete (File : in out File_Type);
  62.    procedure Reset  (File : in out File_Type; Mode : in File_Mode);
  63.    procedure Reset  (File : in out File_Type);
  64.  
  65.    function Mode (File : in File_Type) return File_Mode;
  66.    function Name (File : in File_Type) return String;
  67.    function Form (File : in File_Type) return String;
  68.  
  69.    function Is_Open     (File : in File_Type) return Boolean;
  70.    function End_Of_File (File : in File_Type) return Boolean;
  71.  
  72.    function Stream (File : in File_Type) return Stream_Access;
  73.  
  74.    -----------------------------
  75.    -- Input-Output Operations --
  76.    -----------------------------
  77.  
  78.    procedure Read
  79.      (File : in  File_Type;
  80.       Item : out Stream_Element_Array;
  81.       Last : out Stream_Element_Offset;
  82.       From : in  Positive_Count);
  83.  
  84.    procedure Read
  85.      (File : in  File_Type;
  86.       Item : out Stream_Element_Array;
  87.       Last : out Stream_Element_Offset);
  88.  
  89.    procedure Write
  90.      (File : in File_Type;
  91.       Item : in Stream_Element_Array;
  92.       To   : in Positive_Count);
  93.  
  94.    procedure Write
  95.      (File : in File_Type;
  96.       Item : in Stream_Element_Array);
  97.  
  98.    ----------------------------------------
  99.    -- Operations on Position within File --
  100.    ----------------------------------------
  101.  
  102.    procedure Set_Index (File : in File_Type; To : in Positive_Count);
  103.  
  104.    function Index (File : in File_Type) return Positive_Count;
  105.    function Size  (File : in File_Type) return Count;
  106.  
  107.    procedure Set_Mode (File : in out File_Type; Mode : in File_Mode);
  108.  
  109.    procedure Flush (File : in out File_Type);
  110.  
  111.    ----------------
  112.    -- Exceptions --
  113.    ----------------
  114.  
  115.    Status_Error : exception renames IO_Exceptions.Status_Error;
  116.    Mode_Error   : exception renames IO_Exceptions.Mode_Error;
  117.    Name_Error   : exception renames IO_Exceptions.Name_Error;
  118.    Use_Error    : exception renames IO_Exceptions.Use_Error;
  119.    Device_Error : exception renames IO_Exceptions.Device_Error;
  120.    End_Error    : exception renames IO_Exceptions.End_Error;
  121.    Data_Error   : exception renames IO_Exceptions.Data_Error;
  122.  
  123. private
  124.    package FCB renames System.File_Control_Block;
  125.  
  126.    -----------------------------
  127.    -- Stream_IO Control Block --
  128.    -----------------------------
  129.  
  130.    type Operation is (Op_Read, Op_Write, Op_Other);
  131.    --  Type used to record last operation (to optimize sequential operations)
  132.  
  133.    type Stream_AFCB is new FCB.AFCB with record
  134.       Index : Count := 1;
  135.       --  Current Index value
  136.  
  137.       Last_Op : Operation := Op_Other;
  138.       --  Last operation performed on file, used to avoid unnecessary
  139.       --  repositioning between successive read or write operations.
  140.  
  141.       Update_Mode : Boolean := False;
  142.       --  Set if the mode is changed from write to read or vice versa.
  143.       --  Indicates that the file has been reopened in update mode.
  144.  
  145.    end record;
  146.  
  147.    type File_Type is access all Stream_AFCB;
  148.  
  149.    function AFCB_Allocate (Control_Block : Stream_AFCB) return FCB.AFCB_Ptr;
  150.  
  151.    procedure AFCB_Close (File : access Stream_AFCB);
  152.    procedure AFCB_Free  (File : access Stream_AFCB);
  153.  
  154.    procedure Read
  155.      (File : in out Stream_AFCB;
  156.       Item : out Ada.Streams.Stream_Element_Array;
  157.       Last : out Ada.Streams.Stream_Element_Offset);
  158.    --  Read operation used when Stream_IO file is treated directly as Stream
  159.  
  160.    procedure Write
  161.      (File : in out Stream_AFCB;
  162.       Item : in Ada.Streams.Stream_Element_Array);
  163.    --  Write operation used when Stream_IO file is treated directly as Stream
  164.  
  165. end Ada.Streams.Stream_IO;
  166.